package entity

import (
	"fmt"
	"time"

	"gorm.io/gorm"
	"shqsoft.cn/pas3ui/base"
)

//ShBxzsdr 保险中收导入
type ShBxzsdr struct {
	ID     int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	XH     int       `gorm:"column:XH"`
	SQSJ   time.Time `gorm:"column:SQSJ"`
	BDH    string    `gorm:"column:BDH"`
	XZMC   string    `gorm:"column:XZMC"`
	TBRXM  string    `gorm:"column:TBRXM"`
	JFNQ   string    `gorm:"column:JFNQ"`
	BF     float64   `gorm:"column:BF"`
	SXFLL  float64   `gorm:"column:SXFLL"`
	SXFJE  float64   `gorm:"column:SXFJE"`
	XSRYGH string    `gorm:"column:XSRYGH"`
	XSRYXM string    `gorm:"column:XSRYXM"`
	EMID   int       `gorm:"column:EMID"`
	DRRQ   time.Time `gorm:"column:DRRQ"`
	CZR    string    `gorm:"column:CZR"`
	CZRID  int       `gorm:"column:CZRID"`
	CZRQ   time.Time `gorm:"column:CZRQ"`
}

//TableName
func (ShBxzsdr) TableName() string {
	return "SH_INDI_BXZSDR"
}

// BeforeCreate
func (u *ShBxzsdr) BeforeCreate(tx *gorm.DB) (err error) {
	var emid *int
	tx.Raw(`select "ID" from "T_SysUser" where "SysUserID" = ?`, u.XSRYGH).Row().Scan(&emid)
	if emid == nil {
		err = fmt.Errorf("员工号%s在系统中不存在！", u.XSRYGH)
		return
	}
	u.EMID = *emid
	u.CZRQ = time.Now()
	return
}

//ShCompClieZcldEF 返回结构体
func ShBxzsdrEF() base.EntityFunc {
	return func() interface{} {
		entity := ShBxzsdr{}
		return &entity
	}
}

//ShCompClieZcldESF 返回结构体数组
func ShBxzsdrESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []ShBxzsdr
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("ShBxzsdr", base.NewDefaultDao(ShBxzsdrEF(), ShBxzsdrESF(), nil, "my"))
}
